package cn.im.qywx.wx;

import cn.im.qywx.model.ImWxUserInfo;
import cn.im.qywx.wx.msg.MainClick;
import cn.im.qywx.wx.msg.NoType;
import cn.im.qywx.wx.msg.View;
import cn.im.qywx.wx.type.MessageType;
import cn.im.qywx.wx.type.ModeType;
import org.thymeleaf.util.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description: 消息处理
 */
public abstract class Message {

	/**
	 * 执行消息处理
	 * @param userInfo
	 */
	public abstract void execute(ImWxUserInfo userInfo);
	
	/**
	 * 消息类型处理选择器
	 * @return
	 */
	public static Message messageSelector(ModeType modeType, MessageType messageType){
		switch (modeType) {
			case MAIN:
				switch(messageType){
					//case TEXT: return new MainText();
					//case IMAGE: return new Image();
					//case VOICE: return new MainVoice();
					//case LOCATION: return new Location();
					//case SUBSCRIBE: return new Subscribe();
					//case UNSUBSCRIBE: return new UnSubscribe();
					//case SCAN: return new Scan();
					case CLICK: return new MainClick();
					case VIEW: return new View();
				}
			
			case ARTIFICIAL:
				switch(messageType){
					/*case TEXT: return new ArtificialText();
					case IMAGE: return new ArtificialImage();
					case VOICE:  return new ArtificialVoice();
					case LOCATION: return new Location();
					case CLICK: return new ArtificialClick();
					case SCAN: return new Scan();
					case VIEW: return new View();*/
				}
			
				
			default: return new NoType();
		}
	}
	
	
	private static List<String> msgTypeList;//消息类型集合

	/**
	 * 获取消息类型
	 * @return
	 */
	public static String getMsgType(String msgType) {

		if (null == msgTypeList || msgTypeList.size() <= 0) {
			msgTypeList = new ArrayList<String>();
			msgTypeList.add(MessageType.TEXT.name());
			msgTypeList.add(MessageType.IMAGE.name());
			msgTypeList.add(MessageType.LOCATION.name());
			msgTypeList.add(MessageType.LINK.name());
			msgTypeList.add(MessageType.EVENT.name());
			msgTypeList.add(MessageType.SCAN.name());
			msgTypeList.add(MessageType.SUBSCRIBE.name());
			msgTypeList.add(MessageType.UNSUBSCRIBE.name());
			msgTypeList.add(MessageType.CLICK.name());
			msgTypeList.add(MessageType.MUSIC.name());
			msgTypeList.add(MessageType.NEWS.name());
			msgTypeList.add(MessageType.VOICE.name());
			msgTypeList.add(MessageType.VIEW.name());
		}

		if (!StringUtils.isEmpty(msgType)) {
			msgType = msgType.trim().toUpperCase();
			if (msgTypeList.contains(msgType)) {
				return msgType;
			}
		}

		return MessageType.NOTFOUND.name();
	}

}
